#ifndef PAL_H
#define PAL_H
#include <structure.h>
#include <length.h>

#include <mmuInit.h>
#define PAGE_NORMAL
#define PAGE_SWAP_OUT
//INVALID
#define PAGE_UNALLOCATED
//EMPTY
#define PAGE_COW
//KERNEL READ ONLY

#define SCHEDULE_DEFAULT		(0)
#define SCHEDULE_MUTEX			(1)
#define SCHEDULE_END			(2)
#define SCHEDULE_PROCESS_END		(3)


#define HWREG(x)                        (*((volatile _ptlong *)(x)))
#define ISR_NUM			128
#define TIMER_NUM		8
#define DMA_CHANNEL_NUM		64
#define SYS_ISR_TURN		SYS_INT_TINT2
#define SYS_ISR_TURN_PRI	0

#define DMA_MODE_PASSIVE	0
#define DMA_MODE_ACTIVE		1
#define DMA_MODE_QDMA		2
#define DMA_BLOCK_SIZE		(512)

#ifdef __cplusplus
#define NULL  nullptr
#else
#define NULL ((void*)0)
#endif

#define HIGHB(n)			(0xFFFFFFFF << (sizeof(_ptlong)*8 - n))
#define LOWB(n)				(0xFFFFFFFF >> (sizeof(_ptlong)*8 - n))


#define NOW				(((_tcb*)(run->content))->pPro)
#define NOWT				((_tcb*)(run->content))
#define NOWP				(((_tcb*)(run->content))->init_argv[0])

#define u32				_ptlong

extern volatile ring* run;
extern volatile ring* sleep;


extern void TaskSchedule(_ptlong MARK);

  inline int MMU_INIT();
  inline int MMUEnable();
  inline int MMUDisable();
  inline int MMUSet(_ptlong flag);
  inline int MMUMemoryMap(_ptlong* flpage,_ptlong* phyMem,_ptlong* vMem,_ptlong flags);
  inline int MMUMemroySet(_ptlong* flpage,_ptlong* vMem,_ptlong flag);
  inline int MMUMemoryEqual(_ptlong* flPageA,_ptlong* vMemA,_ptlong* flPageB,_ptlong* vMemB);
  inline _ptlong* MMUGetPMem(_ptlong* flpage, _ptlong* vMem);
  inline int MMUSetVMem(_ptlong* flpage,_ptlong* vMem, _ptlong flags);
  inline int HaveVisitedPMemory(_ptlong* phymem);
  inline int MMUSetFPBaseAddr(_ptlong* phymem);



#endif
